<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('添加项目成员')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-project-member-add" th:object="${project}">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">项目名称：</label>
                <div class="col-sm-8">
                    <input name="projectId" type="hidden" th:value="*{id}">
                    <input name="projectName" class="form-control" type="text" th:field="*{shortTitle}"  disabled>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">员工：</label>
                <div class="col-sm-8">
                    <select name="userId"  class="form-control m-b" required th:with="type=${@customDictService.selectDictOnboardStaff()}">
                        <option value="">--请选择--</option>
                        <option th:each="dict : ${type}" th:text="${dict.name} + '(' + ${dict.idNumber} + ')'" th:value="${dict.userId}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group" th:hidden="${project.projectType} != 'staffing'">
                <label class="col-sm-3 control-label">报价方式：</label>
                <div class="col-sm-8">
                    <select th:name="staffingSetting.quotationType" id="quotationType" class="form-control m-b" th:with="type=${@dict.getType('quotation_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${dict.dictValue == staffingSetting.quotationType}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group" th:hidden="${project.projectType} != 'staffing'">
                <label class="col-sm-3 control-label">报价：</label>
                <div class="col-sm-8">
                    <input name="staffingSetting.quotation" id="quotation" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group"  th:hidden="${project.projectType} != 'staffing'">
                <label class="col-sm-3 control-label">月报价：</label>
                <div class="col-sm-8">
                    <input name="staffingSetting.quotationMonth" id="quotationMonth" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group"  th:hidden="${project.projectType} != 'staffing'">
                <label class="col-sm-3 control-label">日报价：</label>
                <div class="col-sm-8">
                    <input name="staffingSetting.quotationDay" id="quotationDay" class="form-control" type="text" disabled>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">岗位：</label>
                <div class="col-sm-8">
                    <select name="postId" class="form-control m-b">
                        <option value="">请选择</option>
                        <option th:each="post:${posts}" th:value="${post.postId}" th:text="${post.postName}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label" th:classappend="${project.projectType} == 'staffing' ? 'is-required': ''" >进场时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="onboardTime" class="form-control" placeholder="yyyy-MM-dd" type="text" th:required="${project.projectType} == 'staffing'">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="description" class="form-control" rows="6"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: bootstrap-select-js" />
    <script th:inline="javascript">
        var prefix = ctx + "erp/project/" +[[${project.getId()}]] + "/member";
        $("#form-project-member-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-project-member-add').serialize());
            }
        }
        function calculatQuotaion(){
            var quotationType = $('#quotationType').val();
            var quotaion = $('#quotation').val();
            switch (quotationType)
            {
                case 'M':
                    $('#quotationMonth').val(quotaion);
                    $('#quotationDay').val(parseFloat(quotaion/21.75).toFixed(2));
                    break;
                case 'D':
                    $('#quotationMonth').val(quotaion*21.75);
                    $('#quotationDay').val(quotaion);
                    break;
                case 'H':
                    $('#quotationMonth').val(quotaion*21.75*8);
                    $('#quotationDay').val(quotaion*8);
                    break;
                default:

            }
        }
        $(function (){
            $('#quotationType').change(function (){
                calculatQuotaion();
            });
            $('#quotation').blur(function (){
                calculatQuotaion();
            });
        });
        calculatQuotaion();

        $("input[name='onboardTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='departTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>